Skip to content

feat!: React contracts; target-support diagnostic; pruning-off warning - #430

Merged
codecaaron merged 2 commits into
mainfrom
feat/leverage-batch-5
Nov 28, 2026
Merged

codecaaron merged 2 commits into
mainfrom
feat/leverage-batch-5

Conversation

@codecaaron

Copy link
Copy Markdown
Owner

Two changes, one commit each, on top of #429.

.contract() on React chains

A React component can declare typed obligations on whoever renders it, with the same rule shape as Effect UI.

  • An attribute a contract requires becomes a required prop: <Link> without href fails with Property 'href' is missing.
  • A conditional rule applies by variant value, counting the variant's default, and by tag. An icon-only button must carry aria-label or aria-labelledby only when kind is iconOnly; aria-label={undefined} does not discharge it.
  • A state can discharge an obligation (decorative in place of alt).
  • Contracts are inherited through .extend() and kept inside composed families. A rule's attrs are set at run time.
  • The rule types move to @animus-ui/core, so the two bindings share them. Effect UI's fixtures pass unchanged. The extractor already recognised the step; a chain with a contract emits the same CSS as one without.
  • A component with no contract costs nothing extra to type-check. The binding itself costs about 15,600 more instantiations, once per program.
  • Pinned by packages/react/types/published/contract.tsx: 11 negative assertions, each failing on both compilers in both modes when its directive is removed.

Limit: rendering with no props at all against a state-discharge rule (<Picture />) fails without naming the missing attribute.

Target-support diagnostic; pruning-off warning

  • animus.style.unsupported-feature reports a property, at-rule or value function that at least one target browser lacks, located at the property, with feature and reason fields. The data is a table generated from web-features by packages/extract/scripts/css-support.ts (--write / --check): 578 properties, 24 at-rules, about 117 functions, 9 KB gzipped.
  • It does not fire for a feature Lightning CSS lowers for the targets, inside @supports, or when the project sets no targets (browserslist defaults do not count).
  • Kept: packages/_integration/__tests__/target-support.test.ts.
  • animus.usage.pruning-off (warn) names the computed member read that turned option and state pruning off for the whole build, and how many options ship because of it. Before, the only trace was one line under verbose.
  • The showcase had five such reads. Written with .at() and a lookup function it now prunes 17 of 234 options, and its stylesheet drops from 258,938 to 254,141 bytes.

Known weakness: web-features counts a partial implementation as unsupported, so outline is reported for Safari before 16.4. A follow-up will take first-shipped versions instead.

Not covered: keyword-level support, selectors and pseudo-classes, and at-rules outside component styles (@property, @position-try, @keyframes, @font-face).

Release notes

  • New: .contract(rule) on React and .extend() chains. ContractRequirement, ContractRule and ContractRuleEntry are exported from @animus-ui/core and @animus-ui/react.
  • Types: AnimusWithAll, AnimusComponent, AnimusWrappedComponent and the AnimusExtended* classes gain a trailing contracts type parameter. Composed families keep union props of their slots.
  • Breaking: a strict build that sets targets fails when a style uses a feature the targets lack and Lightning CSS does not lower. Set diagnostics: { 'animus.style.unsupported-feature': 'warn' } or 'off' to relax it.
  • New: animus.usage.pruning-off.

Verification

🤖 Generated with Claude Code

codecaaron and others added 2 commits November 28, 2026 04:44
A React component can declare typed obligations on its renders with the same rule shape as Effect UI. A required attribute becomes a required prop; a conditional rule applies by variant value, counting the variant's default, and by tag; a state can discharge an obligation. Contracts are inherited through .extend() and kept inside composed families. Rule attrs are set at run time. The rule types move to @animus-ui/core so the two bindings share them.

AnimusWithAll, AnimusComponent, AnimusWrappedComponent and the AnimusExtended classes gain a trailing contracts type parameter. Composed families keep union props of their slots.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
animus.style.unsupported-feature reports a property, at-rule or value function that a target browser lacks, located at the property, from a table generated out of web-features by css-support.ts. It does not fire for a feature Lightning CSS lowers, inside @supports, or when the project sets no targets. Under strict it fails the build.

animus.usage.pruning-off names the computed member read that turned option and state pruning off for the whole build. The showcase had five such reads; written with .at() and a lookup function it now prunes, and its stylesheet drops from 258,938 to 254,141 bytes.

Verified at this commit: vp run verify:full (55 of 55 tasks); both generators pass --check. The parity baselines are unchanged.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecaaron
codecaaron merged commit 0a8bb43 into main Nov 28, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant